package com.clever.mall.service.impl;

import com.clever.mall.entity.Brand;
import com.clever.mall.mapper.BrandMapper;
import com.clever.mall.service.BrandService;
import com.clever.mall.service.ProductService;
import com.clever.mall.utils.MyBeanUtils;
import com.clever.mall.vo.BrandVo;
import com.clever.mall.vo.ProductVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Resource
    BrandMapper brandMapper;
    @Resource
    ProductService productService;

    //查询热门品牌的前8条
    @Override
    public List<BrandVo> findHeatBrand() {
        List<Brand> brands = brandMapper.selectHeatBrand();
        List<BrandVo> ts = MyBeanUtils.copyListProperties(brands, BrandVo::new);
        return ts;
    }

    //已id查询品牌的详细信息
    @Override
    public BrandVo findById(int id) {
        //查询该品牌的热卖单品
        List<ProductVo> heatByBrandId = productService.findHeatByBrandId(id);
        //查询该品牌的所有商品
        List<ProductVo> allByBrandId = productService.findAllByBrandId(id);
        //已id查询品牌的详细信息
        Brand brand = brandMapper.selectById(id);
        BrandVo brandVo = new BrandVo();
        BeanUtils.copyProperties(brand,brandVo);
        brandVo.setAllList(allByBrandId);
        brandVo.setHeatList(heatByBrandId);
        return brandVo;
    }
}
